package thread;

class SingletonLazy {
    private static SingletonLazy instance = null;
    public static SingletonLazy getInstance() {
        if(instance == null) {
            //如果instance 是null , 说明是首次调用
            //如果是非null ,就说明是后续调用, 就不用加锁
            synchronized (SingletonLazy.class) {
                if(instance == null) {
                    instance = new SingletonLazy();
                }
            }
        }

        return instance;
    }

    private SingletonLazy() {};
}

public class ThreadDemo27 {
    public static void main(String[] args) {
        SingletonLazy singletonLazy1 = SingletonLazy.getInstance();
        SingletonLazy singletonLazy2 = SingletonLazy.getInstance();

        System.out.println(singletonLazy1 == singletonLazy2);

    }
}
